<?php

declare(strict_types=1);

namespace DreamCat\ObjectValidTest\Cases;

use DreamCat\ObjectValid\Annotation\NumberScope;
use DreamCat\ObjectValid\Exception\CheckErrorException;
use DreamCat\ObjectValid\Validor\Validator;
use DreamCat\ObjectValidTest\Helper\DemoPojo;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

/**
 * -
 * @author vijay
 */
class FnValidatorTest extends TestCase
{
    public function testFn()
    {
        $v = new Validator();
        $ref = new ReflectionMethod(DemoPojo::class, "testFn");
        $params = [
            DemoPojo::builder(["value" => 50]),
            35,
        ];
        try {
            foreach ($ref->getParameters() as $idx => $parameter) {
                $param = $params[$idx];
                $v->validParam($parameter, $param);
            }
        } catch (CheckErrorException $exception) {
            self::assertEquals("v 不能大于 30", $exception->getMessage());
            self::assertEquals($params[1], $exception->getValue());
            self::assertEquals(NumberScope::class, get_class($exception->getInvalid()));
            self::assertEquals($ref->getParameters()[1], $exception->getReflection());
        }
    }
}

# end of file
